package com.hspedu.single_;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/27
 * @time 15:39
 */
public class SingleTon01 {

    public static void main(String[] args) {
        GirlFriend instance = GirlFriend.getInstance();
        System.out.println(instance);
    }

}

class GirlFriend{
    private String name;

    private static GirlFriend gf ;

    private GirlFriend(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "GirlFriend{" +
                "name='" + name + '\'' +
                '}';
    }

    public static GirlFriend getInstance(){
        if (gf == null){
            gf = new GirlFriend("小红");
        }
        return gf;
    }

}
